/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.topo.titlegroup;

import java.awt.Rectangle;
import java.awt.event.MouseEvent;

import twaver.Group;
import twaver.TWaverConst;
import twaver.network.ui.ElementUI;
import twaver.network.ui.GroupUI;
import twaver.network.ui.LabelAttachment;

public class TitleGroupLabelAttachment extends LabelAttachment {

    public TitleGroupLabelAttachment(ElementUI ui) {
        super(ui);
    }

    public Rectangle getBounds() {
        Rectangle bounds = super.getBounds();
        if (((GroupUI) this.getElementUI()).getGroup().isExpand()) {
            int width = ((GroupUI) this.getElementUI()).getShape().getBounds().width + 1;
            bounds.width = width;
            return bounds;
        } else {
            return bounds;
        }
    }
    
    
    public void performAction(int gesture, MouseEvent e) {
    	super.performAction(gesture, e);
    	if(gesture == TWaverConst.MOUSE_LEFT_DOUBLE_CLICKED){
    		Group group = (Group)this.getElementUI().getElement(); 
    		group.setExpand(!group.isExpand());
    	}
    }    
}